package net.borlis.sample.services.facade.ws.request;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

/**
 * @author alex@borlis.net on 04.06.2014.
 */
@XmlRootElement
public class VitoCreateRequest {

    @XmlElement(name = "code")
    private String code;

    @XmlElement(name = "name")
    private String name;

    @XmlElement(name = "kid")
    private String kid;

    @XmlElement(name = "countryCode")
    private String countryCode;

    @XmlElement(name = "firstFixedMargin")
    private Double firstFixedMargin;

    @XmlElement(name = "relativeMargin")
    private Double relativeMargin;

    @XmlElement(name = "secondFixedMargin")
    private Double secondFixedMargin;

    @XmlElement(name = "releaseDays")
    private Integer releaseDays;

    @XmlElement(name = "travelDurations")
    private List<TravelDurationRequest> travelDurations;

    public VitoCreateRequest() {
    }

    public VitoCreateRequest(String code, String name, String kid, String countryCode) {
        this.code = code;
        this.name = name;
        this.kid = kid;
        this.countryCode = countryCode;
    }

    public VitoCreateRequest(String code, String name, String kid, String countryCode, Double firstFixedMargin,
                             Double relativeMargin, Double secondFixedMargin, Integer releaseDays,
                             List<TravelDurationRequest> travelDurations) {
        this.code = code;
        this.name = name;
        this.kid = kid;
        this.countryCode = countryCode;
        this.firstFixedMargin = firstFixedMargin;
        this.relativeMargin = relativeMargin;
        this.secondFixedMargin = secondFixedMargin;
        this.releaseDays = releaseDays;
        this.travelDurations = travelDurations;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getKid() {
        return kid;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public Double getFirstFixedMargin() {
        return firstFixedMargin;
    }

    public Double getRelativeMargin() {
        return relativeMargin;
    }

    public Double getSecondFixedMargin() {
        return secondFixedMargin;
    }

    public Integer getReleaseDays() {
        return releaseDays;
    }

    public List<TravelDurationRequest> getTravelDurations() {
        if (travelDurations == null) {
            return new ArrayList<>();
        }
        return travelDurations;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setKid(String kid) {
        this.kid = kid;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public void setFirstFixedMargin(Double firstFixedMargin) {
        this.firstFixedMargin = firstFixedMargin;
    }

    public void setRelativeMargin(Double relativeMargin) {
        this.relativeMargin = relativeMargin;
    }

    public void setSecondFixedMargin(Double secondFixedMargin) {
        this.secondFixedMargin = secondFixedMargin;
    }

    public void setReleaseDays(Integer releaseDays) {
        this.releaseDays = releaseDays;
    }

    public void setTravelDurations(List<TravelDurationRequest> travelDurations) {
        this.travelDurations = travelDurations;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof VitoCreateRequest) {
            VitoCreateRequest other = (VitoCreateRequest) obj;
            EqualsBuilder builder = new EqualsBuilder();
            builder.append(getCode(), other.getCode());
            builder.append(getName(), other.getName());
            builder.append(getKid(), other.getKid());
            builder.append(getCountryCode(), other.getCountryCode());
            builder.append(getFirstFixedMargin(), other.getFirstFixedMargin());
            builder.append(getSecondFixedMargin(), other.getSecondFixedMargin());
            builder.append(getRelativeMargin(), other.getRelativeMargin());
            builder.append(getReleaseDays(), other.getReleaseDays());
            builder.append(getTravelDurations(), other.getTravelDurations());
            return builder.isEquals();
        }
        return false;
    }

    @Override
    public int hashCode() {
        HashCodeBuilder builder = new HashCodeBuilder();
        builder.append(getCode());
        builder.append(getName());
        builder.append(getKid());
        builder.append(getCountryCode());
        builder.append(getFirstFixedMargin());
        builder.append(getSecondFixedMargin());
        builder.append(getRelativeMargin());
        builder.append(getReleaseDays());
        builder.append(getTravelDurations());
        return builder.toHashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append("kid", getKid()).
                append("code", getCode()).
                append("name", getName()).
                append("countryCode", getCountryCode()).
                append("first_fixed_margin", getFirstFixedMargin()).
                append("relative_margin", getRelativeMargin()).
                append("second_fixed_margin", getSecondFixedMargin()).
                append("release_days", getReleaseDays()).
                append("travel_durations", getTravelDurations()).
                toString();
    }
}
